package hiho.ku._1227;

import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int t = in.nextInt();
		for (int i = 0; i < t; i++)
			run(in);
	}
	
	private static void run(Scanner in) {
		int m = in.nextInt();
		int n = in.nextInt();
		double[] x = new double[m];
		double[] y = new double[m];
		for (int i = 0; i < m; i++) {
			x[i] = in.nextDouble();
			y[i] = in.nextDouble();
		}
		if (m < n) {
			System.out.println(-1);
			return;
		}
		int ans = 20000;
		for (int i = 0; i < m; i++) {
			int tmp = check(i, n, m, x, y);
			if (tmp > 0 && tmp < ans)
				ans = tmp;
		}
		System.out.println((ans <= 1000)? ans : -1);
	}
	
	private static int check(int c, int n, int m, double[] x, double[] y) {
		double[] distances = new double[m];
		for (int i = 0; i < m; i++)
			distances[i] = Math.sqrt((x[i] - x[c]) * (x[i] - x[c]) + (y[i] - y[c]) * (y[i] - y[c]));
		Arrays.sort(distances);
		
		double d = distances[n - 1];
		double _d = Math.ceil(d);
		if (_d - d < 1e-8)
			_d = _d + 1;
		if (n < m && distances[n] - _d <= 1e-8)
			return -1;
		return (int)_d;
	}

}
